SET QUOTED_IDENTIFIER ON

GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AzureStorage]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[AzureStorage](
	[AzureStorageId] [uniqueidentifier] NOT NULL,
	[asName] [nvarchar](50) NOT NULL,
	[UserName] [nvarchar](50) NOT NULL,
	[asKey] [nvarchar](256) NOT NULL,
	[asAccountName] [nvarchar](256) NOT NULL,
	[asUrl] [nvarchar](256) NOT NULL,
	[AzureStorageTypeId] [int] NOT NULL,
 CONSTRAINT [PK_T_AzureStorage] PRIMARY KEY CLUSTERED 
(
	[AzureStorageId] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF)
)
END

GO
SET QUOTED_IDENTIFIER ON

GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[AzureStorageType]') AND type in (N'U'))
BEGIN
CREATE TABLE [dbo].[AzureStorageType](
	[AzureStorageTypeId] [int] NOT NULL,
	[astName] [nvarchar](50) NULL,
 CONSTRAINT [PK_T_AzureStorageType] PRIMARY KEY CLUSTERED 
(
	[AzureStorageTypeId] ASC
)WITH (STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF)
)
END

GO
IF NOT EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_AzureStorage_AzureStorageType]') AND parent_object_id = OBJECT_ID(N'[dbo].[AzureStorage]'))
ALTER TABLE [dbo].[AzureStorage]  WITH CHECK ADD  CONSTRAINT [FK_AzureStorage_AzureStorageType] FOREIGN KEY([AzureStorageTypeId])
REFERENCES [dbo].[AzureStorageType] ([AzureStorageTypeId])

GO
IF  EXISTS (SELECT * FROM sys.foreign_keys WHERE object_id = OBJECT_ID(N'[dbo].[FK_AzureStorage_AzureStorageType]') AND parent_object_id = OBJECT_ID(N'[dbo].[AzureStorage]'))
ALTER TABLE [dbo].[AzureStorage] CHECK CONSTRAINT [FK_AzureStorage_AzureStorageType]

GO


insert into AzureStorageType values
(1, 'Table'),
(2, 'Blob'),
(3, 'Queue'),
(4, 'Sql')